home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / egs-tools / egs_dev-disk / egsdemos / moreexamples / propsliders / propsliders.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-06  |  26.9 KB  |  671 lines

  1.                         /*    PropSliders.c
  2.                            This code demonstrates Sliders, how to create,
  3.                            how to read.
  4.  
  5.                            Patrick Hager, Great Valley Products Inc.
  6.                            November 2, 1993
  7.                         */
  8.  
  9.  
  10. #include <stdio.h>
  11. #include "/global/userwindow.h"
  12. #include "/global/egslibraries.h"
  13.  
  14. #include <clib/alib_protos.h>
  15. #include <clib/exec_protos.h>
  16. #include <egs/egsintui.h>
  17. #include <egs/clib/egsintui_protos.h>
  18. #include <egs/pragmas/egsintui_pragmas.h>
  19. #include <egs/egsgadbox.h>
  20. #include <egs/clib/egsgadbox_protos.h>
  21. #include <egs/pragmas/egsgadbox_pragmas.h>
  22. #include <egs/egb/gbtwodimprop.h>
  23. #include <egs/clib/gbtwodimprop_protos.h>
  24. #include <egs/pragmas/gbtwodimprop_pragmas.h>
  25.  
  26.  
  27.  
  28. #define CHOICES_ID  100          // Gadget ID base for 3 Main Window Choice
  29.                                  // Gadgets.
  30.  
  31. #define HORIZ1INT_ID    200      // More Gadget IDs
  32. #define HORIZ1SLIDER_ID 201
  33. #define HORIZ2INT_ID    250
  34. #define HORIZ2SLIDER_ID 251
  35.  
  36. #define VERTI1INT_ID    200
  37. #define VERTI1SLIDER_ID 201
  38. #define VERTI2INT_ID    250
  39. #define VERTI2SLIDER_ID 251
  40.  
  41. #define TWODIM_ID        300
  42. #define TWODIM_INTGAD_X_ID 302
  43. #define TWODIM_INTGAD_Y_ID 304
  44.                                 // Our UserInputWindow structure for the main
  45.                                 // Window.
  46. static struct UserInputWindow Main_Request;
  47.                                 // Our UserInputWindow structure for the
  48.                                 // Horizontal Sliders Example Window.
  49. static struct UserInputWindow Horiz_Request;
  50.                                 // Our UserInputWindow structure for the
  51.                                 // Vertical Sliders Example Window.
  52. static struct UserInputWindow Verti_Request;
  53.                                 // Our UserInputWindow structure for the
  54.                                 // 2-Dim Sliders Example Window.
  55. static struct UserInputWindow TwoDim_Request;
  56.  
  57.  
  58.                                 /* For this example, we are using multiple
  59.                                    windows, so it is necessary to open a
  60.                                    message port of our own, in order for
  61.                                    all the windows to share a port.
  62.                                 */
  63. static struct MsgPort *ExamplePort;
  64.  
  65.  
  66. static BYTE Quit_Example=0;
  67. static WORD Horiz1_Value=0;        // Current value of Horiz Slider 1.
  68. static WORD Horiz2_Value=0;        // Current value of Horiz Slider 2.
  69. static WORD Verti1_Value=0;        // Current value of Verti Slider 1.
  70. static WORD Verti2_Value=0;        // Current value of Verti Slider 2.
  71. static WORD TwoDimX_Value=0;       // Current X value of Two Dim Prop Gadget.
  72. static WORD TwoDimY_Value=0;       // Current Y value of Two Dim Prop Gadget.
  73.  
  74.            // Local PRIVATE function Prototypes.
  75.  
  76. EB_GadBoxPtr Create_Main (UserInputWindowPtr UserWindow);
  77. void GadgetDown_Main (UserInputWindowPtr UserWindow, EI_GadgetPtr iaddress);
  78. void Close_Main (UserInputWindowPtr UserWindow);
  79.  
  80.  
  81. EB_GadBoxPtr Create_Horiz (UserInputWindowPtr UserWindow);
  82. void GadgetDown_Horiz (UserInputWindowPtr UserWindow, EI_GadgetPtr iaddress);
  83. void Redraw_Horiz (UserInputWindowPtr UserWindow);
  84.  
  85. EB_GadBoxPtr Create_Verti (UserInputWindowPtr UserWindow);
  86. void GadgetDown_Verti (UserInputWindowPtr UserWindow, EI_GadgetPtr iaddress);
  87. void Redraw_Verti (UserInputWindowPtr UserWindow);
  88.  
  89. EB_GadBoxPtr Create_TwoDim (UserInputWindowPtr UserWindow);
  90. void GadgetDown_TwoDim (UserInputWindowPtr UserWindow, EI_GadgetPtr iaddress);
  91. void Redraw_TwoDim (UserInputWindowPtr UserWindow);
  92.  
  93. /****************************
  94.       MAIN CODE
  95. ****************************/
  96. void main (void) {
  97.   EI_EIntuiMsgPtr Mesg;
  98.  
  99.   if (OpenEGSLibraries ()) {
  100.     if (ExamplePort = CreatePort (0,0)) {
  101.       Init_UserWindow (&Main_Request, "Slider Example Main Window",WINDOW_NONMODAL,
  102.                        NULL,ExamplePort);
  103.       Init_UserWindow (&Horiz_Request, "Horizontal Sliders Example Window",WINDOW_NONMODAL,
  104.                        NULL,ExamplePort);
  105.       Init_UserWindow (&Verti_Request, "Vertical Sliders Example Window",WINDOW_NONMODAL,
  106.                        NULL,ExamplePort);
  107.       Init_UserWindow (&TwoDim_Request, "TwoDimSliders Example Window",WINDOW_NONMODAL,
  108.                        NULL,ExamplePort);
  109.  
  110.       Main_Request.Create       = Create_Main;
  111.       Main_Request.GadgetDown   = GadgetDown_Main;
  112.       Main_Request.Close        = Close_Main;
  113.  
  114.       Horiz_Request.Create      = Create_Horiz;
  115.       Horiz_Request.GadgetDown  = GadgetDown_Horiz;
  116.       Horiz_Request.Redraw      = Redraw_Horiz;
  117.  
  118.       Verti_Request.Create      = Create_Verti;
  119.       Verti_Request.GadgetDown  = GadgetDown_Verti;
  120.       Verti_Request.Redraw      = Redraw_Verti;
  121.  
  122.       TwoDim_Request.Create     = Create_TwoDim;
  123.       TwoDim_Request.GadgetDown = GadgetDown_TwoDim;
  124.       TwoDim_Request.Redraw     = Redraw_TwoDim;
  125.  
  126.       Main_Request.IDCMPFlags   =
  127.       Horiz_Request.IDCMPFlags  =
  128.       Verti_Request.IDCMPFlags  =
  129.       TwoDim_Request.IDCMPFlags =  EI_iCLOSEWINDOW | EI_iSIZEVERIFY |
  130.                                    EI_iNEWSIZE | EI_iGADGETDOWN;
  131.  
  132.       Main_Request.Flags        =
  133.       Horiz_Request.Flags       =
  134.       Verti_Request.Flags       =
  135.       TwoDim_Request.Flags      =  EI_SIZEBBOTTOM | EI_SIMPLE_REFRESH |
  136.                                    EI_GIMMEZEROZERO;
  137.  
  138.       Main_Request.SysGadgets   =
  139.       Horiz_Request.SysGadgets  =
  140.       Verti_Request.SysGadgets  =
  141.       TwoDim_Request.SysGadgets =  EI_WINDOWCLOSE | EI_WINDOWSIZE |
  142.                                    EI_WINDOWDRAG|EI_WINDOWBACK;
  143.  
  144.       if (Open_UserWindow (&Main_Request,-1,-1)) {
  145.         while (!Quit_Example) {
  146.           WaitPort (ExamplePort);
  147.           while (Mesg=(struct EI_EIntuiMsg *)GetMsg (ExamplePort)) {
  148.             if ( ((WindowInfoPtr)Mesg->IDCMPWindow->UserData)->EventHandler) {
  149.               ((WindowInfoPtr)Mesg->IDCMPWindow->UserData)->EventHandler (Mesg);
  150.             }
  151.           }
  152.         }
  153.         Close_All_UserWindows ();
  154.       }
  155.       else {
  156.         printf ("Couldn't open my window!\n");
  157.       }
  158.       DeletePort (ExamplePort);
  159.     }
  160.   }
  161.   CloseEGSLibraries ();  // after the bracket cause what if I opened 3 but
  162.                          // couldn't find the rest, still need to close the 3.
  163. }
  164.  
  165. /*************************************
  166.    PRIVATE:  Create_Main.
  167.              This routine is called by the UserWindow routines.
  168.              It passes back a GadBoxPtr to the gadgets wanted.
  169. *************************************/
  170. EB_GadBoxPtr Create_Main (UserInputWindowPtr UserWindow) {
  171.   EB_GadBoxPtr root;
  172.   EB_GadContext gadcon;
  173.  
  174.   gadcon = UserWindow->GadCon;
  175.  
  176.   root = EB_CreateVertiBox (gadcon);
  177.   EB_AddLastSon (root,EB_CreateVertiFill (gadcon,0,0));
  178.   EB_AddLastSon (root,EB_CreateTextAction (gadcon,"Horizontal Sliders",CHOICES_ID+0,EB_FILL_ALL));
  179.   EB_AddLastSon (root,EB_CreateVertiFill (gadcon,0,0));
  180.   EB_AddLastSon (root,EB_CreateTextAction (gadcon,"Vertical Sliders",CHOICES_ID+1,EB_FILL_ALL));
  181.   EB_AddLastSon (root,EB_CreateVertiFill (gadcon,0,0));
  182.   EB_AddLastSon (root,EB_CreateTextAction (gadcon,"Two Dimensional Sliders",CHOICES_ID+2,EB_FILL_ALL));
  183.   EB_AddLastSon (root,EB_CreateVertiFill (gadcon,0,0));
  184.   return root;
  185. }
  186.  
  187. /**************************************
  188.     PRIVATE:  GadgetDown_Main.
  189.               This routine handles the gadget down events passed to the
  190.               Main Control Window.
  191. **************************************/
  192. void GadgetDown_Main (UserInputWindowPtr UserWindow, EI_GadgetPtr iaddress) {
  193.  
  194.   switch (iaddress->GadgetID) {
  195.     case CHOICES_ID+0:
  196.       Open_UserWindow (&Horiz_Request,-1,-1);
  197.     break;
  198.     case CHOICES_ID+1:
  199.       Open_UserWindow (&Verti_Request,-1,-1);
  200.     break;
  201.     case CHOICES_ID+2:
  202.       Open_UserWindow (&TwoDim_Request,-1,-1);
  203.     break;
  204.   }
  205. }
  206.  
  207.  
  208.  
  209. /*************************************
  210.    PRIVATE:  Close_Main.
  211.              This routine CANNOT be used to close the Main
  212.              Control Window!!! It is called by the UserWindow
  213.              routines to allow this window to clean up any
  214.              allocated memory.
  215.              To Close the Main Control Window, call
  216.              CloseDown_Main ();
  217. *************************************/
  218. void Close_Main (UserInputWindowPtr UserWindow) {
  219.  
  220.                          // When the main window quits, we all quit!
  221.   Quit_Example = 1;
  222. }
  223.  
  224.  
  225. /************************************************
  226.                Functions for the Horizontal Slider Example Window.
  227. ************************************************/
  228.  
  229.  
  230.  
  231. /*************************************
  232.    PRIVATE:  Create_Horiz.
  233.              This routine is called by the UserWindow routines.
  234.              It passes back a GadBoxPtr to the gadgets wanted.
  235. *************************************/
  236. EB_GadBoxPtr Create_Horiz (UserInputWindowPtr UserWindow) {
  237.   EB_GadBoxPtr root, horiz, box;
  238.   EB_GadContext gadcon;
  239.  
  240.   gadcon = UserWindow->GadCon;
  241.  
  242.   root = EB_CreateVertiBox (gadcon);
  243.   EB_AddLastSon (root,EB_CreateVertiFill (gadcon,0,0));
  244.  
  245.     horiz=EB_CreateHorizBox (gadcon);
  246.     EB_AddLastSon (horiz,EB_CreateHorizFill (gadcon,0,0));
  247.     EB_AddLastSon (horiz,EB_CreateText (gadcon,"Update on release:"));
  248.     EB_AddLastSon (horiz,EB_CreateHorizFill (gadcon,0,0));
  249.                                // Integer Gadgets have no natural borders
  250.                                // around them, so we add it to a back border.
  251.     box=EB_CreateBackBorder (gadcon,EB_CreateIntegerGadget (gadcon,4,3,HORIZ1INT_ID),
  252.                              EB_FILL_ALL);
  253.                                // We don't want the integer gadget to get bigger,
  254.                                // because it still would only have 3 places
  255.                                // (0-100), so we knock its priority to lowest.
  256.     EB_NewPri (box,-1);
  257.     EB_AddLastSon (horiz,box);
  258.     EB_AddLastSon (horiz,EB_CreateHorizFill (gadcon,0,0));
  259.     box=EB_CreateSuperHorizProp (gadcon,120,20,Horiz1_Value,HORIZ1SLIDER_ID,
  260.                                  EB_DEC_UP_LEFT | EB_INC_UP_LEFT);
  261.                                // The sliders will open very small if left to
  262.                                // themselves. Here I demand it opens a bit
  263.                                // larger. Comment out this line, as well as
  264.                                // the next sliders's NewMinWidth to see what I
  265.                                // mean.
  266.     EB_NewMinWidth (box,120);
  267.     EB_AddLastSon (horiz,box);
  268.     EB_AddLastSon (horiz,EB_CreateHorizFill (gadcon,0,0));
  269.   EB_AddLastSon (root,horiz);
  270.     horiz=EB_CreateHorizBox (gadcon);
  271.     EB_AddLastSon (horiz,EB_CreateHorizFill (gadcon,0,0));
  272.     EB_AddLastSon (horiz,EB_CreateText (gadcon,"Update immediatly:"));
  273.     EB_AddLastSon (horiz,EB_CreateHorizFill (gadcon,0,0));
  274.     box=EB_CreateBackBorder (gadcon,EB_CreateIntegerGadget (gadcon,4,3,HORIZ2INT_ID),
  275.                              EB_FILL_ALL);
  276.     EB_NewPri (box,-1);
  277.     EB_AddLastSon (horiz,box);
  278.     EB_AddLastSon (horiz,EB_CreateHorizFill (gadcon,0,0));
  279.     box=EB_CreateSuperHorizProp (gadcon,120,20,Horiz2_Value,
  280.                                                   HORIZ2SLIDER_ID,
  281.                                                   EB_DEC_UP_LEFT | EB_INC_UP_LEFT);
  282.                                  // This slider will now give a gadget down
  283.                                  // message every time its value changes.
  284.                                  // (Make sure you can process this many messages!)
  285.     ((EB_SPropGadPtr)box->Render.Gad)->RealProp->Propflags |= EI_PROP_FOLLOW;
  286.     EB_NewMinWidth (box,120);
  287.     EB_AddLastSon (horiz,box);
  288.     EB_AddLastSon (horiz,EB_CreateHorizFill (gadcon,0,0));
  289.   EB_AddLastSon (root,horiz);
  290.  
  291.   return root;
  292. }
  293.  
  294. /**************************************
  295.     PRIVATE:  GadgetDown_Horiz.
  296.               This routine handles the gadget down events passed to the
  297.               Horiz Control Window.
  298. **************************************/
  299. void GadgetDown_Horiz (UserInputWindowPtr UserWindow, EI_GadgetPtr iaddress) {
  300.   EI_GadgetPtr tgad;
  301.   WORD value;
  302.  
  303.   switch (iaddress->GadgetID) {
  304.     case HORIZ1INT_ID:
  305.       value=((EI_IntGadPtr)iaddress)->Value;
  306.                                // Good value.  Update Slider.
  307.       if ((value>=0)&&(value<100)) {
  308.         Horiz1_Value=value;
  309.         if (tgad=myFindGadget (UserWindow->GadCon,HORIZ1SLIDER_ID)) {
  310.           ((EB_SPropGadPtr)tgad)->RealProp->Value=Horiz1_Value;
  311.           EI_RefreshGadget (UserWindow->Window,tgad);
  312.         }
  313.  
  314.       }
  315.                               // Bad Value. Change Int Gad back to old value.
  316.       else {
  317.         EB_PutIntData (UserWindow->Window,iaddress,Horiz1_Value);
  318.         EI_RefreshGadget (UserWindow->Window,iaddress);
  319.       }
  320.     break;
  321.     case HORIZ1SLIDER_ID:
  322.       if (tgad=myFindGadget (UserWindow->GadCon,HORIZ1INT_ID)) {
  323.         Horiz1_Value=((EB_SPropGadPtr)iaddress)->RealProp->Value;
  324.         EB_PutIntData (UserWindow->Window,tgad,Horiz1_Value);
  325.       }
  326.     break;
  327.     case HORIZ2INT_ID:
  328.       value=((EI_IntGadPtr)iaddress)->Value;
  329.                                // Good value.  Update Slider.
  330.       if ((value>=0)&&(value<100)) {
  331.         Horiz2_Value=value;
  332.         if (tgad=myFindGadget (UserWindow->GadCon,HORIZ2SLIDER_ID)) {
  333.          ((EB_SPropGadPtr)tgad)->RealProp->Value=Horiz2_Value;
  334.           EI_RefreshGadget (UserWindow->Window,tgad);
  335.         }
  336.       }
  337.                               // Bad Value. Change Int Gad back to old value.
  338.       else {
  339.         EB_PutIntData (UserWindow->Window,iaddress,Horiz2_Value);
  340.         EI_RefreshGadget (UserWindow->Window,iaddress);
  341.       }
  342.  
  343.     break;
  344.     case HORIZ2SLIDER_ID:
  345.       if (tgad=myFindGadget (UserWindow->GadCon,HORIZ2INT_ID)) {
  346.         Horiz2_Value=((EB_SPropGadPtr)iaddress)->RealProp->Value;
  347.         EB_PutIntData (UserWindow->Window,tgad,Horiz2_Value);
  348.       }
  349.     break;
  350.   }
  351. }
  352.  
  353. /**************************************
  354.    PUBLIC:  Redraw_Horiz.
  355.             This routine is called on a EI_iREFRESHWINDOW message.
  356.             If you have nothing to refresh, set the Horiz_Request.Refresh
  357.             to NULL.
  358. **************************************/
  359. void Redraw_Horiz (UserInputWindowPtr UserWindow) {
  360.   EI_GadgetPtr tgad;
  361.  
  362.                       // EB_PutIntData automatically refreshes the gadget if
  363.                       // its on screen.
  364.   if (tgad=myFindGadget (UserWindow->GadCon,HORIZ1INT_ID)) {
  365.     EB_PutIntData (UserWindow->Window,tgad,Horiz1_Value);
  366.   }
  367.                       // Since there is no function to update a slider, we
  368.                       // must do it manually, then refresh the gadget ourselves.
  369.   if (tgad=myFindGadget (UserWindow->GadCon,HORIZ1SLIDER_ID)) {
  370.     ((EB_SPropGadPtr)tgad)->RealProp->Value=Horiz1_Value;
  371.     EI_RefreshGadget (UserWindow->Window,tgad);
  372.   }
  373.   if (tgad=myFindGadget (UserWindow->GadCon,HORIZ2INT_ID)) {
  374.     EB_PutIntData (UserWindow->Window,tgad,Horiz2_Value);
  375.   }
  376.   if (tgad=myFindGadget (UserWindow->GadCon,HORIZ2SLIDER_ID)) {
  377.     ((EB_SPropGadPtr)tgad)->RealProp->Value=Horiz2_Value;
  378.     EI_RefreshGadget (UserWindow->Window,tgad);
  379.   }
  380. }
  381.  
  382. /******************************************************
  383.             Functions for the Vertical Sliders Example Window.
  384. *******************************************************/
  385.  
  386.  
  387. /*************************************
  388.    PRIVATE:  Create_Verti.
  389.              This routine is called by the UserWindow routines.
  390.              It passes back a GadBoxPtr to the gadgets wanted.
  391. *************************************/
  392. EB_GadBoxPtr Create_Verti (UserInputWindowPtr UserWindow) {
  393.   EB_GadBoxPtr root, verti, box;
  394.   EB_GadContext gadcon;
  395.  
  396.   gadcon = UserWindow->GadCon;
  397.                               /*  Note the difference in the sizeing of the
  398.                                   Prop gadgets given who they share the Vertical
  399.                                   Box with, the first, a long text string, the
  400.                                   second, a short one...
  401.                               */
  402.  
  403.   root = EB_CreateHorizBox (gadcon);
  404.   EB_AddLastSon (root,EB_CreateHorizFill (gadcon,0,0));
  405.     verti=EB_CreateVertiBox (gadcon);
  406.     EB_AddLastSon (verti,EB_CreateVertiFill (gadcon,0,0));
  407.     EB_AddLastSon (verti,EB_CreateText (gadcon,"Update on release:"));
  408.     EB_AddLastSon (verti,EB_CreateVertiFill (gadcon,0,0));
  409.     box=EB_CreateSuperVertiProp (gadcon,120,20,Verti1_Value,VERTI1SLIDER_ID,
  410.                                  EB_DEC_UP_LEFT | EB_INC_UP_LEFT);
  411.                                // The sliders will open very small if left to
  412.                                // themselves. Here I demand it opens a bit
  413.                                // larger. Comment out this line, as well as
  414.                                // the next sliders's NewMinHeight to see what I
  415.                                // mean.
  416.     EB_NewMinHeight (box,120);
  417.     EB_AddLastSon (verti,box);
  418.                                // Integer Gadgets have no natural borders
  419.                                // around them, so we add it to a back border.
  420.     box=EB_CreateBackBorder (gadcon,EB_CreateIntegerGadget (gadcon,4,3,VERTI1INT_ID),
  421.                              EB_FILL_ALL);
  422.                                // We don't want the integer gadget to get bigger,
  423.                                // because it still would only have 3 places
  424.                                // (0-100), so we knock its priority to lowest.
  425.     EB_NewPri (box,-1);
  426.     EB_AddLastSon (verti,box);
  427.     EB_AddLastSon (verti,EB_CreateVertiFill (gadcon,0,0));
  428.   EB_AddLastSon (root,verti);
  429.     verti=EB_CreateVertiBox (gadcon);
  430.     EB_AddLastSon (verti,EB_CreateVertiFill (gadcon,0,0));
  431.     EB_AddLastSon (verti,EB_CreateText (gadcon,"Con:"));
  432.     EB_AddLastSon (verti,EB_CreateVertiFill (gadcon,0,0));
  433.     box=EB_CreateSuperVertiProp (gadcon,120,20,Verti2_Value,VERTI2SLIDER_ID,
  434.                                  EB_DEC_BOTTOM_RIGHT | EB_INC_UP_LEFT);
  435.                                // The sliders will open very small if left to
  436.                                // themselves. Here I demand it opens a bit
  437.                                // larger. Comment out this line, as well as
  438.                                // the next sliders's NewMinHeight to see what I
  439.                                // mean.
  440.     EB_NewMinHeight (box,120);
  441.                                // This slider will now give a gadget down
  442.                                // message every time its value changes.
  443.                                // (Make sure you can process this many messages!)
  444.     ((EB_SPropGadPtr)box->Render.Gad)->RealProp->Propflags |= EI_PROP_FOLLOW;
  445.     EB_AddLastSon (verti,box);
  446.                                // Integer Gadgets have no natural borders
  447.                                // around them, so we add it to a back border.
  448.     box=EB_CreateBackBorder (gadcon,EB_CreateIntegerGadget (gadcon,4,3,VERTI2INT_ID),
  449.                              EB_FILL_ALL);
  450.                                // We don't want the integer gadget to get bigger,
  451.                                // because it still would only have 3 places
  452.                                // (0-100), so we knock its priority to lowest.
  453.     EB_NewPri (box,-1);
  454.     EB_AddLastSon (verti,box);
  455.     EB_AddLastSon (verti,EB_CreateVertiFill (gadcon,0,0));
  456.   EB_AddLastSon (root,verti);
  457.  
  458.   return root;
  459. }
  460.  
  461. /**************************************
  462.     PRIVATE:  GadgetDown_Verti.
  463.               This routine handles the gadget down events passed to the
  464.               Verti Control Window.
  465. **************************************/
  466. void GadgetDown_Verti (UserInputWindowPtr UserWindow, EI_GadgetPtr iaddress) {
  467.   EI_GadgetPtr tgad;
  468.   WORD value;
  469.  
  470.   switch (iaddress->GadgetID) {
  471.     case VERTI1INT_ID:
  472.       value=((EI_IntGadPtr)iaddress)->Value;
  473.                                // Good value.  Update Slider.
  474.       if ((value>=0)&&(value<100)) {
  475.         Verti1_Value=value;
  476.         if (tgad=myFindGadget (UserWindow->GadCon,VERTI1SLIDER_ID)) {
  477.           ((EB_SPropGadPtr)tgad)->RealProp->Value=Verti1_Value;
  478.           EI_RefreshGadget (UserWindow->Window,tgad);
  479.         }
  480.       }
  481.                               // Bad Value. Change Int Gad back to old value.
  482.       else {
  483.         EB_PutIntData (UserWindow->Window,iaddress,Verti1_Value);
  484.         EI_RefreshGadget (UserWindow->Window,iaddress);
  485.       }
  486.     break;
  487.     case VERTI1SLIDER_ID:
  488.       if (tgad=myFindGadget (UserWindow->GadCon,VERTI1INT_ID)) {
  489.         Verti1_Value=((EB_SPropGadPtr)iaddress)->RealProp->Value;
  490.         EB_PutIntData (UserWindow->Window,tgad,Verti1_Value);
  491.       }
  492.     break;
  493.     case VERTI2INT_ID:
  494.       value=((EI_IntGadPtr)iaddress)->Value;
  495.                                // Good value.  Update Slider.
  496.       if ((value>=0)&&(value<100)) {
  497.         Verti2_Value=value;
  498.         if (tgad=myFindGadget (UserWindow->GadCon,VERTI2SLIDER_ID)) {
  499.           ((EB_SPropGadPtr)tgad)->RealProp->Value=Verti2_Value;
  500.           EI_RefreshGadget (UserWindow->Window,tgad);
  501.         }
  502.       }
  503.                               // Bad Value. Change Int Gad back to old value.
  504.       else {
  505.         EB_PutIntData (UserWindow->Window,iaddress,Verti2_Value);
  506.         EI_RefreshGadget (UserWindow->Window,iaddress);
  507.       }
  508.     break;
  509.     case VERTI2SLIDER_ID:
  510.       if (tgad=myFindGadget (UserWindow->GadCon,VERTI2INT_ID)) {
  511.         Verti2_Value=((EB_SPropGadPtr)iaddress)->RealProp->Value;
  512.         EB_PutIntData (UserWindow->Window,tgad,Verti2_Value);
  513.       }
  514.     break;
  515.   }
  516. }
  517.  
  518. /**************************************
  519.    PUBLIC:  Redraw_Verti.
  520.             This routine is called on a EI_iREFRESHWINDOW message.
  521.             If you have nothing to refresh, set the Verti_Request.Refresh
  522.             to NULL.
  523. **************************************/
  524. void Redraw_Verti (UserInputWindowPtr UserWindow) {
  525.   EI_GadgetPtr tgad;
  526.  
  527.                       // EB_PutIntData automatically refreshes the gadget if
  528.                       // its on screen.
  529.   if (tgad=myFindGadget (UserWindow->GadCon,VERTI1INT_ID)) {
  530.     EB_PutIntData (UserWindow->Window,tgad,Verti1_Value);
  531.   }
  532.                       // Since there is no function to update a slider, we
  533.                       // must do it manually, then refresh the gadget ourselves.
  534.   if (tgad=myFindGadget (UserWindow->GadCon,VERTI1SLIDER_ID)) {
  535.     ((EB_SPropGadPtr)tgad)->RealProp->Value=Verti1_Value;
  536.     EI_RefreshGadget (UserWindow->Window,tgad);
  537.   }
  538.   if (tgad=myFindGadget (UserWindow->GadCon,VERTI2INT_ID)) {
  539.     EB_PutIntData (UserWindow->Window,tgad,Verti2_Value);
  540.   }
  541.   if (tgad=myFindGadget (UserWindow->GadCon,VERTI2SLIDER_ID)) {
  542.     ((EB_SPropGadPtr)tgad)->RealProp->Value=Verti2_Value;
  543.     EI_RefreshGadget (UserWindow->Window,tgad);
  544.   }
  545. }
  546.  
  547.  
  548. /************************************************************
  549.            Functions for the TwoDimensional Prop Gadget Example Window.
  550. ************************************************************/
  551.  
  552.  
  553.  
  554. /*************************************
  555.    PRIVATE:  Create_TwoDim.
  556.              This routine is called by the UserWindow routines.
  557.              It passes back a GadBoxPtr to the gadgets wanted.
  558. *************************************/
  559. EB_GadBoxPtr Create_TwoDim (UserInputWindowPtr UserWindow) {
  560.   EB_GadBoxPtr root, horiz, box;
  561.   EB_GadContext gadcon;
  562.  
  563.   gadcon = UserWindow->GadCon;
  564.  
  565.   root = EB_CreateVertiBox (gadcon);
  566.   box = EGB_CreateTwoDPropGadget (gadcon,120,20,0,120,20,0,TWODIM_ID);
  567.   EB_NewPri (box,-1);
  568.                               // This should work... but it doesn't.
  569.                               // I'll contact Viona, there must be a way...
  570.   ((EGB_TwoDimPropGadPtr)box)->Propflags |= EI_PROP_FOLLOW;
  571.   EB_AddLastSon (root,EB_CreateGroupBorder (gadcon,box,NULL," Two Dim Prop Gadget"));
  572.     horiz=EB_CreateHorizBox (gadcon);
  573.     EB_AddLastSon (horiz,EB_CreateHorizFill (gadcon,0,0));
  574.     EB_AddLastSon (horiz,EB_CreateText (gadcon,"X:"));
  575.     EB_AddLastSon (horiz,EB_CreateHorizFill (gadcon,0,0));
  576.     box=EB_CreateBackBorder (gadcon,EB_CreateIntegerGadget (gadcon,4,3,
  577.                                                             TWODIM_INTGAD_X_ID),
  578.                               EB_FILL_ALL);
  579.     EB_NewPri (box,-1);
  580.     EB_AddLastSon (horiz,box);
  581.     EB_AddLastSon (horiz,EB_CreateText (gadcon,"Y:"));
  582.     EB_AddLastSon (horiz,EB_CreateHorizFill (gadcon,0,0));
  583.     box=EB_CreateBackBorder (gadcon,EB_CreateIntegerGadget (gadcon,4,3,
  584.                                                              TWODIM_INTGAD_Y_ID),
  585.                               EB_FILL_ALL);
  586.     EB_NewPri (box,-1);
  587.     EB_AddLastSon (horiz,box);
  588.     EB_AddLastSon (horiz,EB_CreateHorizFill (gadcon,0,0));
  589.   EB_AddLastSon (root,horiz);
  590.   return root;
  591. }
  592.  
  593. /**************************************
  594.     PRIVATE:  GadgetDown_TwoDim.
  595.               This routine handles the gadget down events passed to the
  596.               TwoDim Control Window.
  597. **************************************/
  598. void GadgetDown_TwoDim (UserInputWindowPtr UserWindow, EI_GadgetPtr iaddress) {
  599.   EI_GadgetPtr tgad;
  600.   WORD value;
  601.  
  602.   switch (iaddress->GadgetID) {
  603.     case TWODIM_ID:
  604.       TwoDimX_Value = ((EGB_TwoDimPropGadPtr)iaddress)->HValue;
  605.       TwoDimY_Value = ((EGB_TwoDimPropGadPtr)iaddress)->VValue;
  606.       if (tgad=myFindGadget (UserWindow->GadCon,TWODIM_INTGAD_X_ID)) {
  607.         EB_PutIntData (UserWindow->Window,tgad,TwoDimX_Value);
  608.       }
  609.       if (tgad=myFindGadget (UserWindow->GadCon,TWODIM_INTGAD_Y_ID)) {
  610.         EB_PutIntData (UserWindow->Window,tgad,TwoDimY_Value);
  611.       }
  612.     break;
  613.     case TWODIM_INTGAD_X_ID:
  614.       value=((EI_IntGadPtr)iaddress)->Value;
  615.                               // Good Value. Change Two D PropGadget.
  616.       if ((value>=0)&&(value<=100)) {
  617.         TwoDimX_Value=value;
  618.         if (tgad=myFindGadget (UserWindow->GadCon,TWODIM_ID)) {
  619.           EGB_ModifyTwoDPropGadget (UserWindow->Window,tgad,120,20,TwoDimX_Value,
  620.                                                             120,20,TwoDimY_Value);
  621.         }
  622.       }
  623.                               // Bad Value. Change Int Gad back to old value.
  624.       else {
  625.         EB_PutIntData (UserWindow->Window,iaddress,TwoDimX_Value);
  626.         EI_RefreshGadget (UserWindow->Window,iaddress);
  627.       }
  628.     break;
  629.     case TWODIM_INTGAD_Y_ID:
  630.       value=((EI_IntGadPtr)iaddress)->Value;
  631.       if ((value>=0)&&(value<=100)) {
  632.         TwoDimY_Value=value;
  633.         if (tgad=myFindGadget (UserWindow->GadCon,TWODIM_ID)) {
  634.           EGB_ModifyTwoDPropGadget (UserWindow->Window,tgad,120,20,TwoDimX_Value,
  635.                                                             120,20,TwoDimY_Value);
  636.         }
  637.       }
  638.                               // Bad Value. Change Int Gad back to old value.
  639.       else {
  640.         EB_PutIntData (UserWindow->Window,iaddress,TwoDimY_Value);
  641.         EI_RefreshGadget (UserWindow->Window,iaddress);
  642.       }
  643.     break;
  644.   }
  645. }
  646.  
  647.  
  648. /**************************************
  649.    PUBLIC:  Redraw_TwoDim.
  650.             This routine is called on a EI_iREFRESHWINDOW message.
  651.             If you have nothing to refresh, set the TwoDim_Request.Refresh
  652.             to NULL.
  653. **************************************/
  654. void Redraw_TwoDim (UserInputWindowPtr UserWindow) {
  655.   EI_GadgetPtr tgad;
  656.  
  657.                       // EB_PutIntData automatically refreshes the gadget if
  658.                       // its on screen.
  659.   if (tgad=myFindGadget (UserWindow->GadCon,TWODIM_INTGAD_X_ID)) {
  660.     EB_PutIntData (UserWindow->Window,tgad,TwoDimX_Value);
  661.   }
  662.   if (tgad=myFindGadget (UserWindow->GadCon,TWODIM_INTGAD_Y_ID)) {
  663.     EB_PutIntData (UserWindow->Window,tgad,TwoDimY_Value);
  664.   }
  665.  
  666.   if (tgad=myFindGadget (UserWindow->GadCon,TWODIM_ID)) {
  667.     EGB_ModifyTwoDPropGadget (UserWindow->Window,tgad,120,20,TwoDimX_Value,
  668.                                                       120,20,TwoDimY_Value);
  669.   }
  670. }
  671.